package org.security.config.web;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;

/**
 * 用于对url做放行
 * @author jt
 * @date 2024/7/21 22:30
 */
@ConditionalOnMissingBean(value = AbstractFreeSecurityWebConfig.class)
public class AbstractFreeSecurityWebConfig implements InitializingBean {

    public final static UrlPermissionConfig urlPermissionConfig =new UrlPermissionConfig();


    public static UrlPermissionConfig.UrlPermission newUrlPermission(String url, UrlPermissionConfig.BasePermissionType permissionType){
        UrlPermissionConfig.UrlPermission urlPermission = new UrlPermissionConfig.UrlPermission(url);
        urlPermission.setPermission(permissionType.name());
        urlPermission.setType(UrlPermissionConfig.Type.no.name());
        return urlPermission;
    }

    public static UrlPermissionConfig.UrlPermission newUrlPermission(String url, UrlPermissionConfig.BasePermissionType permissionType,UrlPermissionConfig.Type type){
        UrlPermissionConfig.UrlPermission urlPermission = new UrlPermissionConfig.UrlPermission(url);
        urlPermission.setPermission(permissionType.name());
        urlPermission.setType(type.name());
        return urlPermission;
    }
    @Override
    public void afterPropertiesSet() throws Exception {
        UrlPermissionConfig.UrlPermission loginUrl = UrlPermissionConfig.UrlPermission.builder()
                .url("login/login").type(UrlPermissionConfig.Type.logout.name()).build();
        this.urlPermissionConfig.urlPermissionList.add(loginUrl);
    }


}
